const jwt = require("jsonwebtoken");
const fs = require('fs');
let private_key = fs.readFileSync('./pem/private_key.pem')

const check = async(token) => {
    if (token) {
        try {
            // 解码
            let payload = await jwt.verify(token, private_key);
            let { iat, exp } = payload;
            let data = new Date().getTime();
            return data - iat * 1000 <= exp * 1000
        } catch(err){
            return false
        }
    }
}

module.exports = check
